<template>
	<view class="logPage">
		<HeaderBar title="兑换记录" showBack fixed backgroundColor="#F6F6F6" />
		<view class="content">
			<scroll-view scroll-y="true" class="scroll-Y" @scrolltolower="addLog">
				<log v-for="i in list" :data="i"></log>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		swapLogs
	} from '@/http/api.js';
	export default {
		data() {
			return {
				page: 1,
				total: 0,
				list: []
			}
		},
		computed: {
			address() {
				return this.$store.getters.getAddress
			},
		},
		mounted() {
			this.swapLogs()
		},
		methods: {
			//获取兑换记录
			swapLogs() {
				uni.showLoading({
					title: '加载中',
					mask: true,
				});
				let parme = {
					address: this.address,
					page: 1
				}
				swapLogs(parme).then(res => {
					uni.hideLoading()
					if (res.code == 200) {
						this.list = res.data.data
						this.total = res.data.total
					}
				}).catch(err => {
					uni.hideLoading()
				})
			},
			addLog() {
				if (this.list.length == this.total) return
				this.page++
				let parme = {
					address: this.address,
					page: this.page
				}
				uni.showLoading({
					title: '加载中',
					mask: true,
				});
				swapLogs(parme).then(res => {
					uni.hideLoading()
					if (res.code == 200) {
						this.list = [...this.list, ...res.data.data]
						this.total = res.data.total
					}
				}).catch(err => {
					uni.hideLoading()
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.logPage {
		height: 100%;
		background: #F6F6F6;
		padding: 0 30upx;
		display: flex;
		flex-direction: column;

		.content {
			flex: 1;
			padding: 20upx 0;
			overflow-y: hidden;

			.scroll-Y {
				height: 100%;

			}
		}
	}
</style>